getImg = function(html){
	
	function xhr(imgLink){
		var 
			 xhr		= new ActiveXObject('MSXML2.XMLHTTP.3.0')
			,domain		= imgLink.match(/http:\/\/[\.\w\d\:]+\//)[0]
			,localLink	= imgLink.split('\/')
			,localLink	= localLink.pop()
			,localLink	= $$.cfg.app_root + 'upload/' + localLink
			,fileName	= Server.mappath(localLink);
			
		with(xhr){
			async = false;
//			setRequestHeader("Referer", domain);
			open("GET", imgLink, false);
			send(null);
			if(readyState == 4){
//				debugger;
			var saver = new ActiveXObject("ADODB.Stream");
				saver.type = 1;
				saver.open();			
				saver.write(responseBody);
				saver.saveToFile(fileName, 2);
			
			}else{
				throw imgLink;
			}
		}
		
		return localLink;
	}
	var 
		 reg = /<img.*?\s+src="(http:\/\/[^"]*)"\s?.*?\/?>/i
		,arr;
	while((arr = reg.exec(html)) != null){
		html = html.replace(arr[1], xhr(arr[1]));
	}
// 不能用replace代替while() 错觉！
//	return html.replace(reg, function(a, b){
//		return a.replace(b, xhr(b));
//	});
	return html;
}
$$.news = {
	create: function(){ 
	    var 
	        SQL    = $$.newInstance($$.sql)
	       ,sql    = "INSERT INTO news (ID, title, content, classID, url, createDate) VALUES ({0}, '{1}', '{2}', {3}, '{4}', #{5} 0:0:0#)".format(
	            new Date().valueOf() // 取得当前的时间戳
	           ,SQL.ESC(Request.Form('title')())
	           ,SQL.ESC(getImg(Request.Form('content')()))
	           ,SQL.ESC(Request.Form('classID')())
	           ,SQL.ESC(Request.Form('url')())
	           ,SQL.ESC(Request.Form('createDate')())
	       )
	       ,entity = $$.sql(sql).rsObj;
	       
	   if(entity.ActiveConnection.Errors.Count == 0){
	       Response.Write('创建成功！');
	   }
	}
	,update: function(){
		/*
		 * 			
		 *  if(key=='ID'){
				value = " Format("+value+",'#0.0000') ";  //双精度转换函数
			}
			if(value && (typeof value.getFullYear == 'function')){//日期类型转换
				value = "#"+ value.format("Y-m-d h:i:s") + "#";
			}
			* {
	 adEmpty : 0,
	 16: 'boolean',//access:16: 'int',
	 2: 'int',
	 3: 'int',
	 20: 'int',
	 17: 'int',
	 18: 'int',
	 19: 'int',
	 21: 'int',
	 4: 'int',
	 5: 'float',
	 6: 'float',
	 14: 'float',
	 131: 'float',
	 11: 'boolean',
	 adError : 10,
	 adUserDefined : 132,
	 adiant : 12,
	 adIDispatch : 9,
	 adIUnknown : 13,
	 adGUID : 72,
	 7 : 'date',
	 133: 'date',
	 134: 'date',
	 135: 'date',
	 8: 'string',
	 129: 'string',
	 200: 'string',
	 201: 'string',
	 130: 'string',
	 202: 'string',
	 203: 'string',
	 adBinary : 128,
	 adBinary : 204,
	 adLongBinary : 205,
	 adChapter : 136,
	 adFileTime : 64,
	 adPropiant : 138,
	 139: 'int'		
	}
		 */
		 debugger;
		 formRequest = $$.server.getRequest_Form_toList(true)
//		sqlESC.map(formRequest);
	    var 
	        fn     = $$.lang.fn
	       ,sqlESC = $$.newInstance($$.sql).ESC
	       ,sql    = "UPDATE news SET title='{0}', content='{1}', url='{2}', classID = {3}, createDate = #{4} 0:0:0# WHERE ID =" + Request.Form('ID')()
	       ,sql    = fn.delgate(''.format, sql)
	       ,sql    = fn.reduce(sql, sqlESC)
	       ,sql    = sql(
	       	 Request.Form('title')()
	       	,getImg(Request.Form('content')())
	       	,Request.Form('url')()
	       	,Request.Form('classID')()
//	       	"#"+ value.format("Y-m-d h:i:s") + "#"
			,Request.Form('createDate')()
	       )
	       ,connObj= (function(sqlObj){
	    	   connObj = sqlObj.connObj;
	    	   connObj.close();
	    	   if(connObj.Errors.Count == 0){
	    		   Response.Write('更新{0}成功！'.format(Request.Form('id')()));
	    	   }
	    	   return connObj;
	       })($$.sql(sql));   
	}
	,'delete':function(){
		
	    var 
	        SQL    = $$.newInstance($$.sql)
	       ,sql    = "DELETE FROM news where ID = " + Request('ID')()
	       ,entity = $$.sql(sql).rsObj;
       
	   if(entity.ActiveConnection.Errors.Count == 0){
	       Response.Write('删除记录成功！');
	   }
       entity.ActiveConnection.close();
	}
	,option: function(){
		
	}
	,'class': {
		create: function(){
			var 
			  title = Request.Form('title')()	
			 ,mediaLogo	= Request.Form('mediaLogo')();
			 
		 if(!title || ! mediaLogo){
		 	throw '表单内容不完整';
		 }
	    var 
	        SQL    = $$.newInstance($$.sql)
	       ,sql    = "INSERT INTO newsClass (ID, title, mediaLogo) VALUES ({0}, '{1}', '{2}')".format(
	            new Date().valueOf() // 取得当前的时间戳
	           ,SQL.ESC(title)
	           ,SQL.ESC(mediaLogo)
	       )
	       ,entity = $$.sql(sql).rsObj;
	      
		   if(entity.ActiveConnection.Errors.Count == 0){
		       Response.Write('创建分类成功！');
		   } 
		   entity.ActiveConnection.close();
		}
		,'delete': function(){
		    var 
		        SQL    = $$.newInstance($$.sql)
		       ,sql    = "DELETE FROM newsClass where ID = " + Request('ID')()
		       ,entity = $$.sql(sql).rsObj;
	       
		   if(entity.ActiveConnection.Errors.Count == 0){
		       Response.Write('删除分类成功！');
		   }
	       entity.ActiveConnection.close();
		}
	}
};